package task;

import edu.buaa.act.helper.CsvGPSFileReader;
import edu.buaa.act.helper.RawDataCleaning;
import edu.buaa.act.helper.Utils;
import edu.buaa.act.model.GPSPoint;
import org.slf4j.Logger;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import static edu.buaa.act.helper.CsvGPSFileReader.*;

/**
 * Created by song on 17-7-6.
 */
public class MaxOverlapTime
{
    private static Logger log = Utils.getDebugLogger();

    public static void main(String[] args)
    {
        try
        {
            String dataPath = args[0];
            File dataFile = Utils.getExistFile(dataPath);
            List<GPSPoint> data = CsvGPSFileReader.readLargeFile(dataFile, " ", CAR_ID, LATITUDE, LONGITUDE, TIMESTAMP);

            double south = Double.parseDouble(args[1]);
            double north = Double.parseDouble(args[2]);
            double west = Double.parseDouble(args[3]);
            double east = Double.parseDouble(args[4]);
            List<GPSPoint> data0 = RawDataCleaning.filterByGeoBound(data, south, north, west, east);

            List<List<GPSPoint>> trajData = RawDataCleaning.separateTrajByCarID(data0);
            RawDataCleaning.assertTimeInc(trajData);

            for(List<GPSPoint> traj : trajData){
                if(traj.size()>=2){
                    long start = traj.get(0).getTime()/1000;
                    long end = traj.get(traj.size()-1).getTime()/1000;
                    System.out.print(start);
                    System.out.print(',');
                    System.out.print(end);
                    System.out.println(',');

                }
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
